package com.boot.dog.common.util;

import com.boot.dog.common.constant.Const;

/**
 * @Author: MaxLv
 * @Date: 2019/12/2
 */
public class Result {

    public static final <T> ApiResult<T> ok() {
        return ok(null);
    }

    public static final <T> ApiResult<T> ok(String message) {
        return ok(message, null);
    }

    public static final <T> ApiResult<T> ok(String message, T t) {
        return of(Const.OK, message, t);
    }

    public static final <T> ApiResult<T> of(T t) {
        return of(Const.OK, null, t);
    }

    public static final <T> ApiResult<T> warn(String message) {
        return of(Const.BAD_REQUEST, message, null);
    }

    public static final <T> ApiResult<T> fail(String message) {
        return of(Const.SERVER_ERROR, message, null);
    }

    private static final <T> ApiResult<T> of(Integer code, String message, T t) {
        ApiResult<T> apiResult = new ApiResult<>(code, message);
        if (t != null) {
            apiResult.setContent(t);
        }
        return apiResult;
    }

}
